#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct BinaryTreeNode
{
    int data;
    struct BinaryTreeNode* left;
    struct BinaryTreeNode* right;
}BTNode;


BTNode* BuyNode(int x)
{
    BTNode* newnode = (BTNode*)malloc(sizeof(BTNode));
    if (newnode == NULL)
    {
        perror("malloc fail!");
        return NULL;
    }
    newnode->data = x;
    newnode->left = newnode->right = NULL;
    return newnode;
}

//1,2,2,3,4,4,3
BTNode* createTree()
{
    BTNode* node1 = BuyNode(1);
    BTNode* node2 = BuyNode(2);
    BTNode* node3 = BuyNode(2);
    BTNode* node4 = BuyNode(3);
    BTNode* node5 = BuyNode(4);
    BTNode* node6 = BuyNode(4);
    BTNode* node7 = BuyNode(3);

    node1->left = node2;
    node1->right = node3;
    node2->left = node4;
    node2->right = node5;
    node3->left = node6;
    node3->right = node7;

    return node1;
}

bool isSameTree(BTNode* p, BTNode* q)
{
    if (p == NULL && q == NULL)
        return true;
    if (p == NULL || q == NULL)
        return false;
    if (p->data != q->data)
        return false;
    return isSameTree(p->left, q->right) && isSameTree(p->right, q->left);
}

bool isSymmetric(BTNode* root) {
    if (root == NULL)
        return false;
    if (isSameTree(root->left, root->right))
        return isSymmetric(root->left) && isSymmetric(root->right);
    else
        return false;
}

int main()
{
    BTNode* root = createTree();
    bool ret = isSymmetric(root);
    if (ret)
        printf("true\n");
}